import UIKit
import RxCocoa
import RxSwift

var bag = DisposeBag()
let subject = PublishSubject<String>()


subject.flatMap { text in
    return Observable.just("text: \(text)")
}.subscribe { (event) in
    print(event)
}

subject.onNext("hello world")

subject.onNext("hello china")

subject.onNext("h")


enum E : Error {
    case demoAError
    case demoBError
}

struct Player {
    var score: BehaviorRelay<Int>
}

let disposeBag = DisposeBag()
let first = BehaviorSubject(value: "👦🏻")
let second = BehaviorSubject(value: "🅰️")

let variable = BehaviorSubject(value: first)

variable.asObservable()
        .flatMap { $0 }
        .subscribe(onNext: { print($0) })
        .disposed(by: disposeBag)

first.onNext("🐱")
variable.onNext(second)
second.onNext("🅱️")
first.onNext("🐶")
